import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.*;

/*
 * @author mkyong
 *
 */
public class Convert 
{
    public static String trimLeft(String s) {
        return s.replaceAll("^\\s+", "");
    }    

    public static String URLSource(String url) 
    {
        String source = "";
        try {
            URL google = new URL(url);
            URLConnection yc = google.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(yc
                        .getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                source += trimLeft(inputLine);
                //                 System.out.println(trimLeft(inputLine));
            }
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return source;
    }     

    public static void main(String [] args){

        System.out.println("Source page: http://www.omnimaga.org/index.php?topic=3412.0;wap2\n");
        String s = URLSource("http://www.omnimaga.org/index.php?topic=3412.0;wap2");

        ArrayList <String> ParserStack = new ArrayList<String> ();
        ArrayList <Web> webStack = new ArrayList<Web> ();

        StringTokenizer st = new StringTokenizer(s, "<>", true);
        while (st.hasMoreTokens()) {
            String str = st.nextToken();
            ParserStack.add(str);
        }

        int header = 1;

        for (int i = 0; i < ParserStack.size(); i++)
        {
            if(ParserStack.get(i).equals("<"))
            {
                i++;
                if(ParserStack.get(i).equals("center"))
                {
                    webStack.add( new Web("tiss", "text-align: " + ParserStack.get(i)));
                }
                if(ParserStack.get(i).equals("title"))
                {
                    i += 2;
                    webStack.add( new Web("title", ParserStack.get(i)));
                }
                if(ParserStack.get(i).equals("strong") || ParserStack.get(i).equals("b"))
                {
                    webStack.add( new Web("format", ParserStack.get(i)));
                }
                else if(ParserStack.get(i).equals("em") || ParserStack.get(i).equals("i"))
                {
                    webStack.add( new Web("format", ParserStack.get(i)));
                }
                else
                {
                    webStack.add( new Web("tag", ParserStack.get(i)));
                }
            }
            if(ParserStack.get(i).equals(">"))
            {
                if(i+1 < ParserStack.size())
                {
                    if(!ParserStack.get(i + 1).equals("<"))
                    {
                        i++;
                        webStack.add( new Web("text", ParserStack.get(i))); 
                    }
                }
            }   
        }

        for ( Web a : webStack )
        {
            System.out.println("Type: " + a.getType() + " Value: " + a.getValue());
        }
    }
}